Micron Document
██████╗ ███████╗████████╗██╗██████╗ ███████╗██████╗ ██╗ █████╗
██╔══██╗██╔════╝╚══██╔══╝██║██╔══██╗██╔════╝██╔══██╗██║██╔══██╗
██████╔╝█████╗ ██║ ██║██████╔╝█████╗ ██║ ██║██║███████║
██╔══██╗██╔══╝ ██║ ██║██╔═══╝ ██╔══╝ ██║ ██║██║██╔══██║
██║ ██║███████╗ ██║ ██║██║ ███████╗██████╔╝██║██║ ██║
╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═╝╚═╝ ╚══════╝╚═════╝ ╚═╝╚═╝ ╚═╝


🬧 The NomadNet Encyclopedia | Archives | Info
- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b- `b

🔍 Search

¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯

JavaScript Object Notation
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
top
mwbwJavaScript Object Notation (mwcaJSON ˈdʒeɪ·səncite-ref-ecma-404-1-0[1]) è un mwdgformato per lo scambio dati basato sul mwdwlinguaggio di programmazione mweaJavaScript (ECMA-262)cite-ref-json-it-2-0[2].

È utilizzato in mwfgprogrammazione web come alternativa al formato mwfwXMLcite-ref-3[3].

Originariamente descritto nella mwhqRFC 4627cite-ref-4[4], è diventato uno mwigstandard mwiwECMA nel 2013 come ECMA-404cite-ref-5[5]cite-ref-6[6]. Nel 2017 è stata pubblicata una seconda edizione del formato che costituisce la base dello standard mwlaISO/mwlqIEC 21778cite-ref-7[7]cite-ref-8[8].

Contents

Formato
Note

──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────

Caratteristiche

La semplicità di JSON format ne ha decretato un rapido utilizzo specialmente nella mwoqprogrammazione in mwogAJAX. Il suo uso tramite JavaScript è particolarmente semplice, infatti l'mwowinterprete è in grado di eseguire il mwpaparsing di una stringa che ne rappresenti un valido contenuto tramite la funzione mwpqJSON.parse()cite-ref-eval-9-0[9]. Questo lo ha reso velocemente molto popolare a causa della diffusione della programmazione in JavaScript nel mondo del mwqgWeb.

I mwratipi di dati supportati da questo formato sono:

• mwrwbooleani (mwsamwsqtrue e mwsgmwswfalse);
• interi, mwtqnumeri in virgola mobile;
• stringhe racchiuse da doppi apici (mwtw");
• mwuqarray (sequenze ordinate di valori, separati da virgole e racchiusi in parentesi quadre mwug[]);
• mwvaarray associativi (sequenze coppie chiave-valore separate da virgole racchiuse in parentesi graffe);
• mwvgmwvwnull.

La maggior parte dei mwwqlinguaggi di programmazione possiede un mwwgtypesystem molto simile a quello definito da JSON per cui sono nati molti progetti che permettono l'utilizzo di JSON con altri linguaggi quali, per esempio: mwwwActionScript, mwxaC, mwxqC#, mwxgAdobe ColdFusion, mwxwCommon LISP, mwyaDelphi, E, mwygErlang, mwywJava, mwzaJavaScript, mwzqLua, mwzgML, mwzwObjective Caml, mwaaPerl, mwaqPHP, mwagPython, mwawREBOL, mwbaRuby e mwbqRust.

Uno mwbwstream JSON dovrebbe avere un'intestazione HTTP mwcaContent-Type: application/jsoncite-ref-10[10].

Fra i primi utilizzatori di JSON si trova mwdgYahoo!, dal 2005cite-ref-11[11].

Relazione con altri linguaggi di markup

Il JSON è un formato di interscambio di dati, ed è spesso comparato con l'mwfqXML che però è un mwfglinguaggio di markup. Entrambi non hanno un sistema di rappresentazione dei dati mwfwbinaricite-ref-12[12], per cui è compito del mwhaprogrammatore adottare convenzioni appropriate (per esempio mwhqBase64) per convertire i dati binari in forma testuale.

Alcune delle limitazioni di JSON sono coperte da mwhwYAMLcite-ref-13[13].

Formato

Il seguente esempio rappresenta i dati di un'ipotetica persona in formato JSON:

{
"name": "Mario",
"surname": "Rossi",
"active": true,
"favouriteNumber": 54,
"birthday": {
"day": 1,
"month": 1,
"year": 2000
},
"languages": [ "it", "en" ]
}

Utilizzi

In JavaScript

Segue un semplice esempio di richiesta mw3gAJAX in JavaScript, ad un mw3wURL che risponda con dati JSON.cite-ref-14[14]

var httpRequest = new XMLHttpRequest();
// callback
httpRequest.addEventListener( 'load', function () {
// parse della risposta (si presume sia in formato JSON)
var data = JSON.parse( this.responseText );
// fare qualcosa con i dati
console.log( data );
} );
// inizializzazione e invio
httpRequest.open( 'GET', 'https://it.wikipedia.org/w/api.php?action=query&prop=info&titles=Pagina+principale&format=json' );
httpRequest.send();

mwat8Applicazioni Mobili

Per far comunicare il mwaueback-end all'mwauiapplicazione mobile è possibile inviare i dati attraverso il mwaumprotocollo mwauqHTTP in formato JSONcite-ref-15[15].

Supporto

In JavaScript

Tra i browser senza il supporto a mwauwmwau0JSONmwau4.mwau8parsemwava() si citano alcune versioni, principalmente precedenti al 2009, in ordine alfabetico:cite-ref-16[16]

• mwavcInternet Explorer precedente alla versione 8
• mwavkMozilla Firefox precedente alla versione 3.5
• mwavsSafari precedente alla versione 4

Un gran numero di librerie semplificarono l'utilizzo del formato JSON per effettuare richieste Ajax. Si citano mwav0JQuery ed mwav4AngularJS.cite-ref-17[17]cite-ref-18[18]

Storicamente vi fu un'indiscriminata adozione del metodo mwawgmwawkevalmwawo() al posto di mwawsmwawwJSONmwaw0.mwaw4parsemwaw8() dato che questi due metodi sono apparentemente interscambiabili. Il metodo mwaxamwaxeevalmwaxi() però non fornisce alcuna protezione da input arbitrario e può portare a serie vulnerabilità.cite-ref-eval-9-1[9]

Si cita il supporto a mwaxgmwaxkXMLHttpRequest in ordine cronologico:cite-ref-can-i-use-xhr3-19-0[19]

• mwayaMozilla Firefox 3.5 (2009)
• mwayiGoogle Chrome 7 (2010)
• mwayqSafari 5 (2010)
• mwayyInternet Explorer 10 (2012)
• Safari e Google Chrome per mwaygiOS 5.1 (2012)

Altre metodologie di supporto

Vi sono altri modi ormai obsoleti per ottenere mwaysstream JSON, per esempio l'uso dell'elemento mwaywmway0<mway4iframemway8> o di mwazaform come mwazemwazi<mwazmform mwazqactionmwazu=mwazy"url_to_cgi_script" mwazctargetmwazg=mwazk"name_of_hidden_iframe"mwazo>. Questi approcci erano largamente usati prima dell'ampio supporto dell'oggetto mwaz0XMLHTTPRequest.

Anche il mwaz8tag mwaaamwaae<mwaaiscriptmwaam> può essere usato per ottenere dati JSON. Questo permette di superare alcune limitazioni che sorgono con l'utilizzo di mwaayXMLHTTPRequest ma a discapito della sicurezza.cite-ref-20[20]

Note

cite-note-ecma-404-11. mwabe(mwabimwabmEN) mwabqmwabuThe JSON Data Interchange Syntax (mwabymwabcPDF), su mwabgecma-international.org, 2ªmwabk ed., dicembre 2017.
cite-note-json-it-22. mwab0mwab4mwab8Introduzione a JSON, su mwacajson.org.
cite-note-33. mwacq(mwacumwacyEN) mwaccmwacgJSON: The Fat-Free Alternative to XML, su mwackjson.org.
cite-note-44. mwac0(mwac4mwac8EN) mwadamwadeRFC 4627 — The application/json Media Type for JavaScript Object Notation (JSON), su mwadidatatracker.ietf.org, mwadmInternet Engineering Task Force.mwadq
cite-note-55. mwadg(mwadkmwadoEN) mwadsmwadwECMA-404 The JSON data interchange syntax, su mwad0ECMA.
cite-note-66. mwaee(mwaeimwaemEN) Tim Bray, mwaeqmwaeuJSON Redux AKA RFC7159, su mwaeyongoing, 6 marzo 2014.
cite-note-77. mwaeo(mwaesmwaewEN) mwae0mwae4RFC 8259 — The JavaScript Object Notation (JSON) Data Interchange Format, su mwae8datatracker.ietf.org, mwafaInternet Engineering Task Force.mwafe
cite-note-88. mwafu(mwafymwafcEN) mwafgmwafkISO/IEC 21778:2017, su mwafomwafsISO.
cite-note-eval-99. mwage(mwagimwagmEN) mwagqmwaguJSON.parse() vs. eval, su mwagystackoverflow.com. mwagcURL consultato il 20 febbraio 2018.
cite-note-1010. mwags(mwagwmwag0EN) mwag4mwag8The application/json encoding algorithm, su mwahamwaheW3C.
cite-note-1111. mwahu(mwahymwahcEN) mwahgmwahkJSON JavaScript Object Notation, su mwahoYahoo!, 19 luglio 2005. mwahsURL consultato il 16 aprile 2015.
cite-note-1212. mwah8mwaiamwaieJSON Documentation, su mwaiifile-types.com, 18 gennaio 2020. mwaimURL consultato il 10 ottobre 2021.
cite-note-1313. La specifica YAML 1.2 fu pubblicata nel 2009. Il suo scopo primario fu quello di rendere YAML un sovrainsieme proprio di JSON.mwaic
cite-note-1414. mwaismwaiwmwai0Usare XMLHttpRequest, su mwai4developer.mozilla.org. mwai8URL consultato il 20 febbraio 2018 mwaja(archiviato dall'mwajeurl originale il 21 febbraio 2018).
cite-note-1515. mwaju(mwajymwajcEN) mwajgmwajkHow to build cross-platform mobile apps using nothing more than a JSON markup, su mwajofreeCodeCamp.org, 12 febbraio 2017. mwajsURL consultato il 17 ottobre 2020.
cite-note-1616. mwaj8(mwakamwakeEN) mwakimwakmCan I use JSON.parse, su mwakqcaniuse.com. mwakuURL consultato il 20 febbraio 2018.
cite-note-1717. mwakk(mwakomwaksEN) mwakwmwak0$http, su mwak4mwak8AngularJS. mwalaURL consultato il 20 febbraio 2018. mwali«The $http service is a core AngularJS service that facilitates communication with the remote HTTP servers via the browser's XMLHttpRequest object or via JSONP.»
cite-note-1818. mwaly(mwalcmwalgEN) mwalkmwalojQuery.getJSON, su mwalsmwalwjQuery. mwal0URL consultato il 20 febbraio 2018. mwal8«Load JSON-encoded data from the server using a GET HTTP request»
cite-note-can-i-use-xhr3-1919. mwamm(mwamqmwamuEN) mwamymwamcCan I use XMLHttpRequest, su mwamgcaniuse.com. mwamkURL consultato il 20 febbraio 2018.
cite-note-2020. mwam0(mwam4mwam8EN) Douglas Crockford, mwanamwaneJSONRequest, su mwanijson.org, 17 aprile 2006. mwanmURL consultato il 20 febbraio 2018.

Bibliografia

• mwanc(EN) T. Bray (a cura di), The JavaScript Object Notation (JSON) Data Interchange Format, su RFC Editor, dicembre 2017, DOI:10.17487/rfc8259.
• mwank(EN) Douglas Crockford, How JSON Works, in How JavaScript Works, Virgule-Solidus, 2018, ISBN 978-1-94-981500-9.

Voci correlate

• mwan0JSONPath
• mwaoeAJAX
• mwaomYAML
• mwaouWeb service
• mwaocS-expression
• mwaokSOAP
• mwaosXML-RPC
• mwao0JSON Fixer

Altri progetti

Altri progetti

• Wikimedia Commons

• Wikimedia Commons contiene immagini o altri file sul JSON

Collegamenti esterni

• (EN) Sito ufficiale, su json.org.
• citereffoldoc(EN) Denis Howe, JavaScript Object Notation, in Free On-line Dictionary of Computing. Disponibile con licenza mwapyGFDL
• mwapg (EN) YUI Library, Douglas Crockford: The JSON Saga, su YouTube, 29 agosto 2011.